package LC;

import java.util.*;

/**
 * @ClassName LC144
 * @Description: TODO
 * @Author hl
 * @Date 2020/5/30
 * @Version V1.0
 **/
public class LC144 {

    //非递归实现前序遍历
 public List<Integer> frontSeach(TreeNode root) {
        List<Integer> list=new ArrayList<>();
        if(root==null){
            return  list;
        }
        Stack<TreeNode> stack=new Stack<>();
        stack.push(root);
        while(!stack.isEmpty()){
            TreeNode temp=stack.pop();
           list.add(temp.val);
            if(temp.right!=null){
                stack.push(temp.right);
            }
            if(temp.left!=null){
                stack.push(temp.left);
            }
        }
        return  list;
 }
}
